define(["jquery","servers"], function ($,servers) {
    return Backbone.Model.extend({
        defaults: function () {
            return {
                defUploadImgUrl:servers.base.uploadImg,
                defUploadFile:servers.base.uploadFile
            };
        },
        getIndustry:function () {
            var self=this;
            servers.base.industry(function(res){
                var list=[];
                if(res.success){
                    list=$.map(res.data,function(info){
                        return {id:info.id, text:info.name, originalName:info.name, parent:info.parentId===0?"#":info.parentId};
                    });
                }
                res.data=list;
                self.set({dataIndustry:res});
                self.trigger('bind:Industry');
            });
        },
        getCrowdBag:function () {
            var self=this;
            servers.base.crowdBag(function(res){
                res.data=res.success ? $.ExtCommon.convertListByPara(res.data) : [];
                self.set({dataCrowdBag:res});
                self.trigger('bind:CrowdBag');
            });
        },
        getSpreadType:function () {
            var self=this;
            servers.base.spreadType(function(res){
                var list=[];
                if(res.success){
                    list=$.map(res.data,function (info) {
                        var newInfo= $.ExtCommon.getMappingJson(info,{id:"id",name:"name"},true);
                        var typeMap=servers.base.getMapSpreadType(newInfo.id.toString()).idMap;
                        newInfo.isOrdinary=typeMap==="1";
                        newInfo.isWeChat=typeMap==="2";
                        return newInfo;
                    });
                }
                res.data=list;
                self.set({dataSpreadType:res});
                self.trigger('bind:SpreadType');
            });
        },
        /*getSpeedMode:function () {
            var self=this;
            servers.base.speedMode(function(res){
                res.data=res.success ? $.ExtCommon.convertListByPara(res.data) : [];
                self.set({dataSpeedMode:res});
                self.trigger('bind:SpeedMode');
            });
        },*/
        getObjMatterType:function () {
            var self=this;
            servers.base.objMatterType(function(res){
                var group={};
                var list=[];
                if(res.success){
                    for(var i=0;i<res.data.length;i++){
                        var newInfo=$.ExtCommon.getMappingJson(res.data[i],{id:"id",name:"name",type:"type"},true);
                        var id=newInfo.id.toString();
                        var mapInfo=servers.base.getMapObjMatterType(id);
                        newInfo.isOrdinary=mapInfo.idMap==="1";
                        newInfo.isAndroid=mapInfo.idMap==="2";
                        newInfo.isIos=mapInfo.idMap==="3";
                        newInfo.isWeChat=mapInfo.idMap==="4";
                        newInfo.matterTypeFilter=mapInfo.filterType;
                        if(!$.ExtCommon.isCheckEmpty(newInfo.type)){
                            var type=newInfo.type.toString();
                            if(!group.hasOwnProperty(type)){group[type]=[]}
                            group[type].push(newInfo);
                        }
                        list.push(newInfo)
                    }
                }
                self.set({dataObjMatterType:servers.getSendSuccess({list:list,group:group})});
                self.trigger('bind:ObjMatterType');
            });
        },
        getChannelPack:function (param) {
            var self=this;
            var newParam=$.ExtCommon.getMappingJson(param, {campaignId:"campaignId",markType:"objMatterType",appId:"apkId"});
            servers.base.channelPack(newParam,function(res){
                res.data=res.success ? $.ExtCommon.convertListByPara(res.data) : [];
                self.set({dataChannelPack:{req:param,res:res}});
                self.trigger('bind:ChannelPack');
            });
        },
        getDeliveryTimeType:function () {
            var newJson=[{id:"1",name:"长期投放",isLong:true,isRange:false},{ id: "2", name: "时段投放",isLong:false,isRange:true}];
            this.set({dataDeliveryTimeType:servers.getSendSuccess(newJson)});
            this.trigger('bind:DeliveryTimeType');
        },
        getResourceType:function (id) {
            var self=this;
            servers.base.resourceType({advertiserId:id},function(res){
                var newJson=[];
                if(res.success){
                    newJson=$.map(res.data,function (info) {
                        var newInfo= $.ExtCommon.getMappingJson(info,{id:"id",title:"name",url:"url",disabled:"enable"},true);
                        newInfo.disabled=$.ExtCommon.isCheckBoolean(newInfo.disabled)?!newInfo.disabled:false;
                        return newInfo;
                    });
                }
                self.set({dataResourceType:servers.getSendSuccess(newJson)});
                self.trigger('bind:ResourceType');
            });
        }
    });
});